package com.bw.lib_widget.dialog;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import com.bw.lib_widget.R;
import com.bw.lib_widget.action.ClickAction;
import com.bw.lib_widget.action.SingleClick;
import com.hjq.shape.view.ShapeTextView;


/**
 * @ClassName com.tc.datingta.xdialog.AddressDialog
 * @Author 刘亚西
 * @CreateDate 2022/12/6 14:41
 * @Copyright 南京寻优信息科技有限公司
 * @Description
 **/
public class AppUpdateDialog {

    public static final class Builder extends BaseDialog.Builder<Builder> implements ClickAction {

        private TextView content;
        private ShapeTextView btnConform;
        private TextView btnCancel;
        private TextView tvVersion;

        private OnListener mListener;

        public Builder(Context context) {
            super(context);
            setContentView(R.layout.dialog_app_update);
            setGravity(Gravity.CENTER);
            content = findViewById(R.id.content);
            btnConform = findViewById(R.id.btn_conform);
            btnCancel = findViewById(R.id.btn_cancel);


            tvVersion = findViewById(R.id.tv_version);

            setOnClickListener(btnConform, btnCancel);
        }

        public Builder setListener(OnListener listener) {
            mListener = listener;
            return this;
        }

        public Builder setContent(String str, String str1) {
            tvVersion.setText(str);
            String sa1 = str1.replace("\\n", "\n");
            String sa = sa1.replace("\\r", "\r");
            content.setText(sa);
            return this;
        }


        @SingleClick
        @Override
        public void onClick(View view) {
            int viewId = view.getId();
            if (viewId == R.id.btn_conform) {
                dismiss();
                if (mListener == null) {
                    return;
                }
                mListener.onSelected(getDialog());
            } else if (viewId == R.id.btn_cancel) {
                dismiss();
                if (mListener == null) {
                    return;
                }
                mListener.onCancel(getDialog());
            }
        }
    }

    public interface OnListener {

        void onSelected(BaseDialog dialog);

        /**
         * 点击取消时回调
         */
        default void onCancel(BaseDialog dialog) {
        }
    }
}
